<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:insert="~{include :: header('用户列表')}" />
	<th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
	<div class="toolbar" id="toolbar" role="group">
		<form id="formId">
			<div class="form-inline">
				<a class="btn btn-success mr-1" onclick="$.operate.add(0,'800px','500px')" shiro:hasPermission="manager:add">
					<i class="fa fa-plus"></i> 新增
				</a>
				<input type="text" class="form-control mr-1" name="searchKey" placeholder="管理员Id/名称/手机">
				<button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
					<i class="fa fa-search"></i>
					搜索
				</button>
				<button type="button" class="btn btn-default" onclick="$.form.reset()">
					<i class="fa fa-refresh"></i>
					重置
				</button>
			</div>
		</form>
	</div>
	<table id="bootstrap-table" class="table-striped"></table>
</div>

<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
	var editFlag = [[${@permission.hasPermi('manager:edit')}]];
	var removeFlag = [[${@permission.hasPermi('manager:remove')}]];
	var prefix = "/manager";

	$(function() {
		var options = {
			showSearch: false,
			showRefresh: false,
			showToggle: false,
			showColumns: false,
			url: prefix + "/list.json",
			createUrl: prefix + "/add.html",
			updateUrl: prefix + "/edit.html?id={id}",
			removeUrl: prefix + "/remove.json",
			sortName: "managerId",
			sortOrder: "desc",
			modalName: "用户",
			columns: [
				{
					field: 'managerId',
					title: 'id'
				},
				{
					field: 'managerName',
					title: '姓名'
				},
				{
					field: 'mobile',
					title: '手机'
				},

				{
					field: 'createTime',
					title: '创建时间',
					sortable: true
				},
				{
					field: 'lastLoginTime',
					title: '最后登录',
					sortable: true
				},
				{
					title: '状态',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.managerId + '\',\'800px\',\'500px\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.managerId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						actions.push("<a class='btn btn-info btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authRole(" + row.managerId + ")'><i class='fa fa-check-square-o'></i>分配角色</a> ");
						/*actions.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='resetPwd(" + row.managerId + ")'><i class='fa fa-key'></i>重置密码</a> ");*/
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});

	/* 用户管理-重置密码 */
	function resetPwd(managerId) {
		var url = prefix + '/resetPwd/' + managerId;
		$.modal.open("重置密码", url, '800', '300');
	}

	/* 用户管理-分配角色 */
	function authRole(managerId) {
		var url = prefix + '/authRole/' + managerId;
		$.modal.openTab("用户分配角色", url);
	}

	/* 用户状态显示 */
	function statusTools(row) {
		if (row.isDisabled == 1) {
			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.managerId + '\')"></i> ';
		} else {
			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.managerId + '\')"></i> ';
		}
	}

	/* 用户管理-停用 */
	function disable(managerId) {
		$.modal.confirm("确认要停用用户吗？", function() {
			$.operate.post(prefix + "/disabled.json", { "managerId": managerId, "isDisabled": 1 });
		})
	}

	/* 用户管理启用 */
	function enable(managerId) {
		$.modal.confirm("确认要启用用户吗？", function() {
			$.operate.post(prefix + "/disabled.json", { "managerId": managerId, "isDisabled": 0 });
		})
	}
</script>
</body>
</html>